package IO;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
 * Hash 
 * 
 * @author Incalza Dario
 *
 */
public class Hash {
	/**
	 * Hash een string met behulp van SHA-256 algoritme
	 * @param password
	 * @return hashed password
	 */
	public static String getHash(String password){
			
	        MessageDigest md = null;
	        
			try {
				md = MessageDigest.getInstance("SHA-256");
			} catch (NoSuchAlgorithmException e) {
				
				e.printStackTrace();
			}
			
	        md.update(password.getBytes());
	 
	        byte byteData[] = md.digest();
	 
	        StringBuffer hexString = new StringBuffer();
	    	for (int i=0;i<byteData.length;i++) {
	    		String hex=Integer.toHexString(0xff & byteData[i]);
	   	     	if(hex.length()==1) hexString.append('0');
	   	     	hexString.append(hex);
	    	}
	    	
	    	return hexString.toString();
			
		}

}
